import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:toys_flutter/pages/user/MyGift.dart';
import 'package:toys_flutter/pages/user/MyRoom.dart';

class MyMenu extends StatelessWidget {
  const MyMenu({super.key});

  // 数字大小
  static const double mainFontSize = 16;

  // 图标数据列表
  final List<Map<String, dynamic>> menuItems = const [
    {
      'assetUrl': 'images/icon-vip-user-3.png',
      'label': 'VIP',
    },
    {
      'assetUrl': 'images/icon_tui_guang-3.png',
      'label': '我要推广',
    },
    {
      'assetUrl': 'images/icon-zhibo-3.png',
      'label': '直播',
    },
    {
      'assetUrl': 'images/icon-gift-3.png',
      'label': '我的礼物',
      'page': MyGift(),
    },
    {
      'assetUrl': 'images/icon-liao-tian-shi.png',
      'label': '我的聊天室',
      'page': MyRoom(),
    },
    {
      'assetUrl': 'images/icon-kefu.png',
      'label': '客服',
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(15, 0, 15, 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Padding(
            padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
            child: Text(
              '我的功能',
              style: TextStyle(
                fontSize: 16,
              ),
            ),
          ),
          Wrap(
            children: List.generate(menuItems.length, (index) {
              return SizedBox(
                width: (MediaQuery.of(context).size.width - 32) / 4, // 每个子组件的宽度
                height: 100,
                child: Center(
                  child: InkWell(
                    onTap: () {
                      if (menuItems[index]['page'] != null) {
                        Get.to(menuItems[index]['page']);
                      } else {
                        print(menuItems[index]['label']);
                      }
                    },
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        TDImage(
                          assetUrl: menuItems[index]['assetUrl'],
                          width: 55,
                          height: 55,
                          type: TDImageType.roundedSquare,
                        ),
                        const SizedBox(height: 5),
                        Text(
                          menuItems[index]['label'],
                          style: const TextStyle(fontSize: 10),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }),
          )
        ],
      ),
    );
  }
}
